$(document).ready(function(){	
	$("#addUser").val(username);
	var src = tl_config.his_url;
	var i = src.indexOf('?');
	var jj =src.indexOf('&specId');
	var jjj=src.indexOf('&specName');
	//var jjj=src.indexOf('&cateId');
	if(i!=-1){
		var cateId=src.substring(i+17,jj);
		var specId = src.substring(jj+8,jjj);
		var specName=src.substring(jjj+10);	
		$("#cateId").text(cateId);		
	    $("#specId").val(specId);
	    $("#productSpecName").text(specName);
	}
	/**
	gridObj = $.fn.bsgrid.init('g_tabYeh', {
		ajaxType : 'get',
		url :  server_url+'/rest/ProductValue/ProductSpecValueList.do?ran=' + Math.random() + '&token=' + token,
		autoLoad : true,
		pageSizeSelect : true,
		stripeRows : true,
		pageSize : 10,
		displayBlankRows : false,
		isProcessLockScreen : true,
		rowSelectedColor : false,
		showPageToolbar:true
	});*/
	
//表单验证
var validate = $("#fromProductSpecValue").validate({		   
		rules:{					
			specValueName:{
				  required:true,
			     /* remote: { 
	                   url: server_url+'/rest/ProductValue/checkSpecValueName.do?timestamp='+Math.random()+ '&token=' + token,
	                   type: "post",
	                   dataType: "json", 
	                   data: {			                	     
	                	         specValueName: function() { return $("#specValueName").val();}
	                         } 
	               },*/
	               stringMaxLength:30
			},
		   sortNum:{
			   required:true,
			   stringMaxLength:30
		   }			
		},
		messages:{				
			specValueName:{
			      required:"该值不能为空！",
                 
                  stringMaxLength:"最多能输入30个字符！"
                 },
            sortNum:{
            	 required:"该值不能为空！请输入有效的数字！",
             }
		},
		submitHandler:function(){
			sub();
		},
		errorPlacement: function(error, element) {
			if ( element.is(":radio") )
				error.appendTo ( element.parent() );
			else if ( element.is(":checkbox") )
				error.appendTo ( element.parent() );
			else if ( element.is("input[name=captcha]") )
				error.appendTo ( element.parent() );
			else
				error.insertAfter(element);
		},
		validClass : 'rightValidate',
	    success: function(label) {
		   label.html("&nbsp;").text(" ") ;
	    }
 });
   

});
//添加列表行
function toProductSpecValueAdd(key,value){
	if(key == undefined || key == null){
		key = "";
	}
	if(value == undefined || value == null){
		value = "";
	}
	// 表示现在到第几行
	var index = $("#fromProductSpecValue [name=specValueName]").size();
			$("#table").append(""+
					'<tr id="keyValue'+index+'Tr">' +
     				    		'<td><input type="text" class="t" value="" id="specValueName" name="specValueName" maxlength="30" /></td>'+
     				    		'<td><input type="checkbox" value="1" checked="checked" id="isValidate" name="isValidate"  style="width:20px;margin-top:10px;"/></td>'+
     				    		'<td><input type="text" class="t" value="" id="sortNum" name="sortNum" maxlength="30" onpropertychange="if(/[^0-9]/g.test(this.value)) value=value.substring(0,value.length-1);" maxlength=10 size=8//></td>'+
     				    		'<td><input type="text" class="t" value="" id="remark" name="remark" maxlength="30" /></td>'+
     				    		//'<input name="key" id="key'+index+'" type="hidden" value="'+key+'" maxlength="100"/>' +
     				    		'<td><a href="javascript:delRow('+index+');" class="z_delpost">删除</a></td>'+
     				    	"</tr>"
     				    
		);
	
}
//删除列表行
function delRow(index) {
	$("#keyValue"+index+"Tr").remove();
}
//添加列表行隐藏值
function setKeyValue(index) {
	var keyValue = $('#keyValue'+index).val();
	$('#key'+index).val(keyValue);
}

//提交
function sub(){
	var str= $("#fromProductSpecValue").serialize();
	if(str.indexOf("specValueName")<=0){
		easyDialog.open({container:{header:'温馨提示',content:"属性值不能为空，请维护"},autoClose : 2000});
		return;
	}

		if($("#fromProductSpecValue").valid()){
			$.ajax({
				url:server_url+'/rest/ProductValue/ProductValueAdd.do?ran='+Math.random()+ '&token=' + token,
				type:'post',
				data:$("#fromProductSpecValue").serialize(),
				success:function(data){
					easyDialog.open({container:{header:'温馨提示',content:data.retMsg},autoClose : 2000});
					toback();
				}
			});
		}	
}

function toback(){
	var url="productSpecList.do?ran="+Math.random();
	tl_config.loadToWorkArea(url);
}

function submitCommit(){
	$("#fromProductSpecValue").submit();
}
